package com.xudu.controller.impl;


import com.xudu.common.Result;
import com.xudu.controller.IStudentScoreController;
import com.xudu.service.IStudentScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.security.auth.Subject;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xudu
 * @since 2024-04-25
 */
@RestController
@Slf4j
@EnableAsync
public class StudentScoreControllerImpl implements IStudentScoreController {

    @Autowired
    private IStudentScoreService iStudentScoreService;

    private static final ThreadLocal<Double> ScoreThreadLocal = new ThreadLocal<>();
    @Override
    public Result getAverageGrade(String subject) {

        double res = iStudentScoreService.calculateAverageGrade(subject);
        log.info("{}controller层输出",res);
        return Result.success(res);
    }


    @Override
    public Result calculateScores() {
        // 触发异步操作来计算和更新总成绩
        //iStudentScoreService.calculateOrUpdateSum();
        //iStudentScoreService.calculateOrUpdateSum1();
        iStudentScoreService.calculateOrUpdateSum2();
        log.info("controller执行……");
        return Result.success();
    }
}
